package cn.wjh.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wjh.common.annotation.Log;
import cn.wjh.common.core.controller.BaseController;
import cn.wjh.common.core.domain.AjaxResult;
import cn.wjh.common.enums.BusinessType;
import cn.wjh.business.domain.TranslateHistory;
import cn.wjh.business.service.ITranslateHistoryService;
import cn.wjh.common.utils.poi.ExcelUtil;
import cn.wjh.common.core.page.TableDataInfo;

/**
 * 翻译记录Controller
 *
 * @author jiraWu
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/business/TranslateHistory")
public class TranslateHistoryController extends BaseController {
    @Resource
    private ITranslateHistoryService translateHistoryService;

    /**
     * 查询翻译记录列表
     */
//    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:list')")
    @GetMapping("/list")
    @Cacheable(value = "translateHistoryListCache", keyGenerator = "cacheKeyGenerator")
    public TableDataInfo list(TranslateHistory translateHistory) {
        startPage();
        List<TranslateHistory> list = translateHistoryService.selectTranslateHistoryList(translateHistory);
        return getDataTable(list);
    }

    /**
     * 导出翻译记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:export')")
    @Log(title = "翻译记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TranslateHistory translateHistory) {
        List<TranslateHistory> list = translateHistoryService.selectTranslateHistoryList(translateHistory);
        ExcelUtil<TranslateHistory> util = new ExcelUtil<TranslateHistory>(TranslateHistory.class);
        util.exportExcel(response, list, "翻译记录数据");
    }

    /**
     * 获取翻译记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:query')")
    @GetMapping(value = "/{translateHistoryId}")
    @Cacheable(value = "translateHistoryListCache", keyGenerator = "cacheKeyGenerator")
    public AjaxResult getInfo(@PathVariable("translateHistoryId") Long translateHistoryId) {
        return success(translateHistoryService.selectTranslateHistoryByTranslateHistoryId(translateHistoryId));
    }

    /**
     * 新增翻译记录
     */
    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:add')")
    @Log(title = "翻译记录", businessType = BusinessType.INSERT)
    @PostMapping
    @CacheEvict(value = "translateHistoryListCache", allEntries = true)
    public AjaxResult add(@RequestBody TranslateHistory translateHistory) {
        return toAjax(translateHistoryService.insertTranslateHistory(translateHistory));
    }

    /**
     * 修改翻译记录
     */
    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:edit')")
    @Log(title = "翻译记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @CacheEvict(value = "translateHistoryListCache", allEntries = true)
    public AjaxResult edit(@RequestBody TranslateHistory translateHistory) {
        return toAjax(translateHistoryService.updateTranslateHistory(translateHistory));
    }

    /**
     * 删除翻译记录
     */
    @PreAuthorize("@ss.hasPermi('business:TranslateHistory:remove')")
    @Log(title = "翻译记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{translateHistoryIds}")
    @CacheEvict(value = "translateHistoryListCache", allEntries = true)
    public AjaxResult remove(@PathVariable Long[] translateHistoryIds) {
        return toAjax(translateHistoryService.deleteTranslateHistoryByTranslateHistoryIds(translateHistoryIds));
    }
}
